<!DOCTYPE html>
<html>

<head>
  <meta charset=utf-8>
  <meta name=viewport content="initial-scale=1,maximum-scale=1,user-scalable=no">
  <meta name=format-detection content="telephone=no">

  <title>PDF阅读器</title>
  <style>
    .pdf_header {
      position: fixed;
      left: 0;
      top: 0;
      right: 0;
      color: #FFF;
      font-size: 14px;
      padding-left: 12px;
      overflow: auto;
    }

    .pdf_header > img {
      display: inline-block;
      vertical-align: middle;
      width: 20px;
      height: 20px;
    }

    .pdf_header > .close {
      display: inline-block;
      color: #FFF;
      vertical-align: middle;
      font-size: 16px
    }
  </style>
</head>

<body>
<div class="pdf_header" id='head'>
  <img src="./static/back.png" alt="" onclick="page.backLastPage()">
  <div class="close" onclick="page.backLastPage()">关闭</div>
</div>
</body>
<script>
  var page = {
    backLastPage: function() {
      var iframe = document.parentElement;
      if (!iframe){
        return;
      }
      iframe.style.display = "none";
    }
  };
  var pdf = '', dark = false;
  apiready = function() {
    var reader = api.require('pdfReader');
    pdf = api.pageParam.pdf;
    dark = api.pageParam.dark;
    api.setStatusBarStyle({style: 'light', color: 'rgba(0,0,0,0)', animated: false});
    document.getElementById('head').style.paddingTop = (api.safeArea.top + 8) + 'px';
    reader.openView({
      rect: {x: 0, y: api.safeArea.top + 50, w: api.winWidth, h: api.winHeight - api.safeArea.top - 50},
      path: pdf,
      fixedOn: 'pdf',
      fixed: true,
      showLoading: false
    });
    page.backLastPage = function() {
      api.animation({
          name: 'pdf',
          delay: 0,
          duration: 200,
          curve: 'ease_in_out',
          repeatCount: 0,
          autoreverse: false,
          alpha: 1,
          translation: {x: 0, y: api.winHeight, z: 0}
        },
        function(ret, err) {
          if (ret) {
            if (dark) {
              api.setStatusBarStyle({style: 'dark', color: 'rgba(0,0,0,0)', animated: false});
            }
            reader.closeView();
            api.closeFrame({name: 'pdf'});
          }
        });
    };
  };

</script>

</html>
